package org.yx.service.sres.save_device_maintain_detail;

import org.yx.exception.BizException;
import org.yx.models.SresMtnDtl;
import org.yx.utils.BaseService;
import org.yx.utils.FieldMap;

import com.xiaoleilu.hutool.collection.CollUtil;

/**
 * 
 * @author zxw
 * @since 2019/09/02
 **/
public class SresSaveDeviceMaintainDetailService extends BaseService {
	public SresSaveDeviceMaintainDetailOut saveDeviceMaintainDetail(SresSaveDeviceMaintainDetailIn in) throws Exception {
		if (CollUtil.isEmpty(in.getDetailList())) {
			throw new BizException("SYS-0004", FieldMap.of("parameter", "detailList"));
		}

		for (SresMtnDtl detail : in.getDetailList()) {
			detail.setOrgCode(in.getUserOrgCode());
			if (detail.getStatus() == null) {
				detail.setStatus('N');
			}
			if(detail.getNoticeFlag()==null){
				detail.setNoticeFlag('Y');
			}
		}

		upsertBatch(in.getDetailList());

		SresSaveDeviceMaintainDetailOut out = new SresSaveDeviceMaintainDetailOut();

		return out;
	}
}